local physicsModule = require("physics")
physicsModule.start()

local function createBlock()
	local obj = display.newImage( "bottomHalf.png" )
	obj.y = display.contentHeight - 100
	physicsModule.addBody( obj, { density=3.0, friction=0.1, bounce=0.7 } )
	obj.gravityScale = 0.7
	obj:applyForce( 600, -600, obj.x, obj.y )
	return obj
end

local function createSensor()
	local dummy = display.newImage( "bottomHalf.png" )
	function dummy:collision( event )
		if event.phase == "began" then
			print("sensor")
			event.other:applyForce( 600, -600, event.other.x, event.other.y )
		end
	end
	physicsModule.addBody( dummy, { isSensor = true } )
	dummy.gravityScale = 0
	dummy:addEventListener("collision", dummy)
	return dummy
end

local function createGround()
	local ground = display.newImage( "bottom.png" )
	ground.y = display.contentHeight - ( ground.height / 2 )
	physicsModule.addBody( ground, "static", { density=3.0, friction=0.1, bounce=0.5 } )
	return ground
end

local function setUp()
	createGround()

	local block = createBlock()
	function block:collision(event)
		print( "collision : " .. event.phase )
	end
	block:addEventListener("collision", block)

	local dummy = createSensor()
	dummy.x = display.contentCenterX
	dummy.y = block.y
end

function main()
	setUp()
end

main()
